package com.r_z.controller;


import com.r_z.entity.Storages;
import com.r_z.entity.StoragesDetails;
import com.r_z.result.CommonResult;

import com.r_z.service.impl.StoragesImplService;
import com.r_z.util.RequestMsg;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("storages")
public class StoragesController {
    @Autowired
    private StoragesImplService storages;

    /**
     * 分页查询入库
     *
     * @param page    当前页
     * @param limit   显示数
     * @param nowTime 入库时间
     * @return CommonResult 泛型
     */
    @PostMapping("/selectStorages")
    public CommonResult<Storages> selectStorages(int page, int limit, String nowTime, @RequestParam(value = "storageinState", defaultValue = "3") int storageinState) {
        List<Storages> storagesList = storages.selectStorages(page, limit, nowTime, storageinState);
        int sum = storages.getTotal(nowTime, storageinState);
        return RequestMsg.msg(sum, storagesList);
    }

    /**
     * 查询采购详情
     *
     * @param purchaseId 采购id
     * @return 详情数据
     */
    @GetMapping("/selectDetail")
    public CommonResult<StoragesDetails> selectDetail(String purchaseId) {
        StoragesDetails storagesDetails = storages.selectDetail(purchaseId);
        return RequestMsg.msg(storagesDetails);
    }

    @PostMapping("/approve")
    public int approve(String purchaseId, int goodId, int num) {
        return storages.approve(purchaseId,goodId,num);
    }
}
